package com.sitia.jd.util;

import com.sitia.common.enums.OperatorType;
import com.sitia.common.utils.DateUtils;
import com.sitia.common.utils.ip.IpUtils;
import com.sitia.system.domain.SysOperLog;
import com.sitia.system.mapper.SysOperLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 日志工具类
 */
@Component
public class LogUtil {

    @Autowired
    private SysOperLogMapper logMapper;

    private static LogUtil logUtil;
    @PostConstruct
    public void init() {
        logUtil = this;
        logUtil.logMapper = this.logMapper;
    }


    /**
     * 添加日志，操作类型为新增
     * @param title 标题
     * @param method 方法
     * @param param 参数
     * @param result 结果
     * @param  status 状态 0正常 1异常
     */
    public static void addLog(String title,String method,String param,String result,Integer status) {
        SysOperLog sysOperLog = new SysOperLog();
        sysOperLog.setOperIp(IpUtils.getIpAddr())
                .setTitle(title).setOperLocation(IpUtils.getHostIp())
                .setMethod(method)
                .setOperParam(param)
                .setJsonResult(result)
                .setOperTime(DateUtils.getNowDate())
                .setStatus(status);
        logUtil.logMapper.insertOperlog(sysOperLog);
    }


}
